package MyThread;

public class SellTicket implements Runnable{
    private  int ticket = 100;
    private  boolean loop = true;

    public synchronized void m(){
        if(ticket <= 0){
            System.out.println("售罄！");
            loop = false;
            return;

        }

        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("当前窗口："+Thread.currentThread().getName() + "购票成功，当前剩余票数："+ (--ticket));
    }

    @Override
    public void run() {
        while(loop){
            m();
        }
    }
}
